package com.hbd.esdemo.controller;

import com.hbd.esdemo.EsDemoApplication;
import com.hbd.esdemo.model.Result;
import com.hbd.esdemo.pojo.ShipAddress;
import com.hbd.esdemo.service.impl.ShipAddressServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * 收货地址业务单元测试
 *
 * @author bdhong
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = EsDemoApplication.class)
public class ShipAddresstest {

    @Autowired
    private ShipAddressServiceImpl shipAddressService;


    /**
     * 根据查询条件获取列表信息
     */
    @Test
    public void testList() {

//        String address = "深圳";
//        String address = "asdfasdf深圳";
//        String address = "asdfasdf";
//        String address = "";
        String address = null;

        Result<Iterable<ShipAddress>> iterableResult = Result.buildSuccess(shipAddressService.list(address));
        iterableResult.getData().forEach(System.out::println);
    }

    /**
     * 根据查询条件获取列表信息分页
     */
    @Test
    public void testPage() {

//        String address = "深圳";
//        String address = "asdfasdf深圳";
//        String address = "asdfasdf";
//        String address = "";
        String address = null;
        int page = 1;
        int size = 2;

        Result<Page<ShipAddress>> pageResult = Result.buildSuccess(shipAddressService.page(address, page, size));
        Page<ShipAddress> data = pageResult.getData();
        pageResult.getData().forEach(System.out::println);
    }
}
